<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>联系人信息</title>

	<link rel="stylesheet" href="../css/style.css">
	<link rel="stylesheet" href="../css/common.css">
	<link rel="stylesheet" type="text/css" href="../css/public.css"/>
	<link rel="stylesheet" href="../css/swiper.min.css">
	<script src="../js/index1.js"></script>
	<script src="../js/jquery.js"></script>
	<script src="../js/dyselect.js"></script>
	<script src="../js/swiper.min.js"></script>
	<script src="../js/rem-config.js"></script>


</head>
<body>
<div class="tabbar">
	<a href="mine.html" class="tabbar_r">
		<img src="../images/x.png" >
	</a>
	<span>联系人信息</span>
	<a href="" class="tabbar_c">
		<img src="../images/caidan.png" alt="">
	</a>
	<div class="clear"></div>
</div>
<div class="f_banner">
	<img src="../images/banner.jpg" alt="">
</div>
<div class="progress_bar">
	<div class="yellow"></div>
	<div class="yellow"></div>
	<div class="yellow"></div>
	<div class="yellow"></div>
	<div class="yellow"></div>
	<div class="yellow"></div>
	<div class="yellow"></div>
</div>
<div class="phone_content">
	<div class="contacts_title">
		<p>家庭联系人信息</p>
	</div>
	<ul>
		<li>
			<span>家庭联系人</span>
			<input type="text" placeholder="家庭联系人" class="phone_num reg_jt">
		</li>
		<li>
			<span>和我的关系</span>
			<div class="phone_yunying1 btn1">
				<span class="reg_guanxi">关系</span>
				<img src="../images/xiaosanjiao.png" alt="">
			</div>
		</li>
		<li>
			<span>联系人电话</span>
			<input type="text" placeholder="请输入手机号" class="phone_num reg_phone">
		</li>
	</ul>
	<div class="contacts_title">
		<p>常用联系人信息</p>
	</div>
	<ul>
		<li>
			<span>家庭联系人</span>
			<input type="text" placeholder="常用联系人" class="phone_num reg_jt1">
		</li>
		<li>
			<span>和我的关系</span>
			<div class="phone_yunying1 btn2">
				<span class="reg_guanxi1">关系</span>
				<img src="../images/xiaosanjiao.png" alt="">
			</div>
		</li>
		<li>
			<span>联系人手机</span>
			<input type="text" placeholder="请输入手机号" class="phone_num reg_phone2">
		</li>
	</ul>
</div>
<div class="btn_box">
	<div>上一步</div>
	<div class="next_btn">下一步</div>
</div>
<div class="msg"></div>
<div class="dialog show1">
	<div class="dialog_bg"></div>
	<div class="dialog_info">
		<ul>
			<li>java开发工程师</li>
			<li>java开发工程师</li>
			<li>java全栈开发工程师</li>
		</ul>
		<a href="javascript:;" class="dialog_btn show1_cancle">取消</a>
	</div>
</div>
<div class="dialog show2">
	<div class="dialog_bg"></div>
	<div class="dialog_info">
		<ul>
			<li>6+12个月</li>
			<li>6+18个月</li>
			<li>12个月</li>
		</ul>
		<a href="javascript:;" class="dialog_btn show2_cancle">取消</a>
	</div>
</div>
</body>
<script>
    $(function() {
        $(".btn1").click(function() {
            $(".show1").show();
            $.ajax({
                url:appPath+"withguanxiDropdownBox",
                data:"",
                dataType:'json',//服务器返回json格式数据
                type:'get',//HTTP请求类型
                success:function(res){
                    if(res.success){
                        var _list = res.data;
                        var _li = "";
                        for(var i = 0;i<_list.length;i++){
                            _li+="<li li_id="+_list[i].id+">"+_list[i].name+"</li>";

                        }
                        $(".dialog.show1 ul").html(_li);

                    }else{
                        $(".msg").show().text("获取失败！原因"+res.errorMessage);
                        setTimeout(function(){
                            $(".msg").hide("slow")
                        },2000)
                    }
                }
            });
        })
        $(".show1_cancle").click(function() {
            $(".show1").hide();
        })
        $('.btn2').click(function() {
            $(".show2").show();
            $.ajax({
                url:appPath+"withguanxiDropdownBox",
                data:"",
                dataType:'json',//服务器返回json格式数据
                type:'get',//HTTP请求类型
                success:function(res){
                    if(res.success){
                        var _list = res.data;
                        var _li = "";
                        for(var i = 0;i<_list.length;i++){
                            _li+="<li li_id="+_list[i].id+">"+_list[i].name+"</li>";

                        }
                        $(".dialog.show2 ul").html(_li);

                    }else{
                        $(".msg").show().text("获取失败！原因"+res.errorMessage);
                        setTimeout(function(){
                            $(".msg").hide("slow")
                        },2000)
                    }
                }
            });
        })
        $('.show2_cancle').click(function() {
            $(".show2").hide();
        })


        // 获取文字再放上去
        $(".dialog").on("click","li",function() {
            var li_text = $(this).text();
            var li_id = $(this).attr("li_id")
            if ($(this).parent().parent().parent().hasClass("show1")) {
                $(".btn1 span").text(li_text);
                //获取id属性
                $(".btn1 span").attr("li_id",li_id);

            }else{
                $(".btn2 span").text(li_text);
                $(".btn2 span").attr("li_id",li_id);
            }
            $(".dialog").hide();
        })

        $('.next_btn').click(function(){
            //判断是否为空
            $(".reg_jt").blur(function(){
                if($(this).val()==""){
                    $(".msg").show().text("不能为空");
                    $(this).focus();
                    setTimeout(function(){
                        $(".msg").hide("slow")
                    },2000)

                    return false;
                }
            });
            $(".reg_phone").blur(function(){
                if($(this).val()==""){
                    $(".msg").show().text("不能为空");
                    $(this).focus();
                    setTimeout(function(){
                        $(".msg").hide("slow")
                    },2000)

                    return false;
                }else{
                    var _phone = $(this).val();

                    var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;
                    if(!myreg.test(_phone)){
                        $(".msg").show().text("手机号不合法");
                        setTimeout(function(){
                            $(".msg").hide("slow")
                        },2000);
                        $(this).focus();
                    }
                }
            });
            $(".reg_jt1").blur(function(){
                if($(this).val()==""){
                    $(".msg").show().text("不能为空");
                    $(this).focus();
                    setTimeout(function(){
                        $(".msg").hide("slow")
                    },2000)

                    return false;
                }
            });
            $(".reg_phone2").blur(function(){
                if($(this).val()==""){
                    $(".msg").show().text("不能为空");
                    $(this).focus();
                    setTimeout(function(){
                        $(".msg").hide("slow")
                    },2000)

                    return false;
                }else{
                    var _phone = $(this).val();

                    var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;
                    if(!myreg.test(_phone)){
                        $(".msg").show().text("手机号不合法");
                        setTimeout(function(){
                            $(".msg").hide("slow")
                        },2000);
                        $(this).focus();
                    }
                }
            });
            if($('.reg_guanxi').text()=="关系"){
                $(".msg").show().text("不能为空");
                setTimeout(function(){
                    $(".msg").hide("slow")
                },2000)
                return false;
            };
            if($('.reg_guanxi1').text()=="关系"){
                $(".msg").show().text("不能为空");
                setTimeout(function(){
                    $(".msg").hide("slow")
                },2000)
                return false;
            };

            var _jiating = $('.reg_jt').val();
            var _guanxi = $('.reg_guanxi').attr("li_id");
            var _phone = $('.reg_phone').val();
            var _jiating1 = $('.reg_jt1').val();
            var _guanxi1 = $('.reg_guanxi1').attr("li_id");
            var _phone1 = $('.reg_phone2').val();
            var _data = {
                "familyContacts":_jiating,
                "relationsWithMe":parseInt(_guanxi),
                "contactTelephone":_phone,
                "commonFamilyContacts":_jiating1,
                "commonRelationsWithMe":parseInt(_guanxi1),
                "commonPhone":_phone1
            }
				$.ajax({
					url:appPath+"addContacts",
                    data:JSON.stringify(_data),
                    contentType: "application/json;charset=utf-8",
					dataType:'json',//服务器返回json格式数据
					type:'post',//HTTP请求类型
					success:function(res){
						if(res.success){
							$('.msg').show().text("成功！1秒后跳转")
							setTimeout(function(){
								window.location.href = "phone_authentication.html"
							},1000)
						}else{
							$('.msg').show().text("失败！原因"+res.errorMessage)
							setTime(function(){
								$('.msg').hide("slow")
							},2000)
						}
					},
				});
				
			})
		
		});
	</script>
</html>
